package com.dmap.community.controller.app;

import com.dmap.base.vo.BaseVo;
import com.dmap.community.bo.theme.ShowThemeBo;
import com.dmap.community.constant.Constant;
import com.dmap.community.controller.app.param.CollectParam;
import com.dmap.community.service.community.CollectService;
import com.dmap.community.vo.NormalResponseVo;
import com.dmap.community.vo.theme.ShowThemeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * \* User: silent
 * \* Date: 15/11/17 Time: 10:48
 * \* Description:
 * \
 */
@Api(value = "社区收藏", description = "App/社区收藏")
@RestController
@RequestMapping(value = "/api/dmap-community-server/v1/community/collect")
public class CollectController {
    @Resource
    private CollectService collectService;


    @ResponseBody
    @ApiOperation(value = "社区收藏", notes = "社区收藏")
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public BaseVo insertReply(@RequestBody CollectParam param) {
        BaseVo result = new BaseVo();
        if (param.getThemeId() == 0 || param.getUserId() == 0) {
            result.setCode(Constant.RESPONSE_PARAM_ERROR);
            result.setMsg(Constant.RESPONSE_PARAM_ERROR_MSG);
            return result;
        }
        int success = collectService.insertCollect(param.getThemeId(), param.getUserId());
        if (success == 0) {
            result.setCode(Constant.RESPONSE_INSERT_ERROR);
            result.setMsg(Constant.RESPONSE_INSERT_ERROR_MSG);
        }
        return result;
    }

    @ResponseBody
    @ApiOperation(value = "取消收藏", notes = "取消收藏")
    @RequestMapping(value = "/delete/{themeId}/{userId}", method = RequestMethod.DELETE)
    public BaseVo deleteReplyPraise(@PathVariable(value = "themeId") long themeId, @PathVariable(value = "userId") long userId) {
        BaseVo result = new BaseVo();
        if (themeId == 0) {
            result.setCode(Constant.RESPONSE_PARAM_ERROR);
            result.setMsg(Constant.RESPONSE_PARAM_ERROR_MSG);
            return result;
        }
        int success = collectService.deleteCollectByThemeId(themeId, userId);
        if (success == 0) {
            result.setCode(Constant.RESPONSE_DELETE_ERROR);
            result.setMsg(Constant.RESPONSE_DELETE_ERROR_MSG);
        }
        return result;
    }

    @ResponseBody
    @ApiOperation(value = "查询历史收藏", notes = "查询历史收藏")
    @RequestMapping(value = "history/select", method = RequestMethod.GET)
    public ShowThemeVo selectThemeByType(@RequestParam long userId, @RequestParam Integer pageIndex, @RequestParam Integer pageSize) {
        ShowThemeVo result = new ShowThemeVo();
        if (userId == 0) {
            result.setCode(Constant.RESPONSE_PARAM_ERROR);
            result.setMsg(Constant.RESPONSE_PARAM_ERROR_MSG);
            return result;
        }
        List<ShowThemeBo> showThemeBos = collectService.showThemeListByUserId(userId, pageIndex, pageSize);
        result.setData(showThemeBos);
        return result;
    }


}
